package com.studentrecipe.controller;

import com.studentrecipe.mapper.MapperRegister;
import com.studentrecipe.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@CrossOrigin
public class ControllerRegister {

    @Autowired
    private MapperRegister mapperRegister;

    @RequestMapping("/register")
    public Result register(String username, String password) {
        if(mapperRegister.registerCheck(username) == null) {
            if (mapperRegister.register(username, password) > 0) {
                return Result.success("/login");
            }
            else{
                return Result.fail("Register Failed");
            }
        }
        else{
            return Result.fail("Account Existed");
        }
    }

}
